#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
#if 1
int n;
int a[maxn];
int cnt[maxn];
int main() {
  cin>>n; for(int i=0; i<n; ++i) cin>>a[i];
  int l, r; l = r = 0;
  int ans = -1;
  while(r<n) {
    while(r<n && cnt[a[r]]==0) {cnt[a[r++]]++;}
    ans = ans>=(r-l)? ans: (r-l);
    while(l<r && cnt[a[r]]!=0) {cnt[a[l++]]--;}
  }
  cout << ans << endl;
}
#else
int n, a[maxn], cnt[maxn];
int ans = 1;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  cin>>n;
  for(int i=0; i<n; ++i) cin>>a[i];
  int l=0, r=0;
  while(r<n) {
    while(!cnt[a[r]] && r<n) {
      cnt[a[r]]++;
      r++;
      ans = max(ans, r-l);
    }
    while(cnt[a[r]] && l<r) {
      cnt[a[l]]--;
      l++;
    }
    ans = max(ans, r-l);
  }
  cout<<ans<<'\n';
  return 0;
}
#endif
